package com.niuyubo.listmap;

import com.alibaba.fastjson.JSON;

import java.util.*;

public class ListMapDemo {
    public static void main(String[] args) {
        Map<String, Object> res = new HashMap<>();
        res.put("name", "Jerry");
        res.put("hobby", Arrays.asList("football", "piano"));

        Map<String, Object> school = new HashMap<>();
        res.put("school", school);
        school.put("name", "hahaha");
        school.put("address", "shenzhen");

        Map<String, String> teacher1 = new HashMap<>();
        Map<String, String> teacher2 = new HashMap<>();
        List<Map<String, String>> teachers = Arrays.asList(teacher1, teacher2);
        school.put("teachers", teachers);
        teacher1.put("name", "teacher1");
        teacher1.put("address", "shenzhen");
        teacher2.put("name", "teacher2");
        teacher2.put("address", "shanghai");

        String resline = JSON.toJSONString(res);
        System.out.println(resline);


    }

    static void demo1() {
        List<String> list1 = new ArrayList<>();
        list1.add("q1");
        list1.add("q2");
        List<String> list2 = Arrays.asList("q1", "q2");
        list2.add("q3");
        List<String> list3 = new ArrayList<>(list2);
        list3.add("q4");
        System.out.println(list1);
        System.out.println(list2);
        System.out.println(list3);
    }


    static void demo2() {
        Map<String, Object> res = new HashMap<>();
        res.put("name", "Tom");
        res.put("hobby", Arrays.asList("game", "piano"));

        Map<String, Object> school = new HashMap<>();
        school.put("name", "wiwqio");
        school.put("address", "xinjiang");

        Map<String, String> teacher1 = new HashMap<>();
        teacher1.put("name", "teahcer1");
        teacher1.put("address", "xinjiang");

        Map<String, String> teacher2 = new HashMap<>();
        teacher1.put("name", "teahcer2");
        teacher1.put("address", "xizang");

        List<Map<String, String>> teachers = new ArrayList<>();
        teachers.add(teacher1);
        teachers.add(teacher2);

        school.put("teachers", teachers);

        res.put("shcool", school);

        System.out.println(res);
        String resline = JSON.toJSONString(res);
        System.out.println(resline);

    }









}
